﻿using System;

namespace QuanLyKTX
{
    using DAL;
    using System.Linq;
    using Utilities;

    public partial class frm_ReportIncomeBill : Telerik.WinControls.UI.RadForm
    {

        public int MaPhieuThu { get; set; }

        public frm_ReportIncomeBill()
        {
            InitializeComponent();
        }

        public frm_ReportIncomeBill(int maPhieuThu)
        {
            InitializeComponent();
            MaPhieuThu = maPhieuThu;
        }

        private void frm_ReportIncomeBill_Load(object sender, EventArgs e)
        {
            using (var db = new QuanLyKTXDataContext())
            {
                var result = (from p in db.tbl_PhieuThus
                              where p.MaPhieuThu == MaPhieuThu
                              select new
                              {
                                  p.MaPhieuThu,
                                  p.HauTo,
                                  p.NgayLapPhieu,
                                  p.HoTenNguoiNop,
                                  p.DiaChi,
                                  p.LyDoNop,
                                  p.SoTien,
                                  TienThanhChu = new CNumToString().convertStart(String.Format("{0:0.##}",p.SoTien))
                                  
                              }).FirstOrDefault();

                System.Data.DataRow dr = dataSetPhieuThu.Tables[0].NewRow();
                dr["MaPhieuThu"] = result.MaPhieuThu;
                dr["HauTo"] = result.HauTo;
                dr["NgayLapPhieu"] = result.NgayLapPhieu;
                dr["HoTenNguoiNop"] = result.HoTenNguoiNop;
                dr["DiaChi"] = result.DiaChi;
                dr["LyDoNop"] = result.LyDoNop;
                dr["SoTien"] = result.SoTien;
                dr["TienThanhChu"] = result.TienThanhChu;

                dataSetPhieuThu.Tables[0].Rows.Add(dr);

                reportViewer_IncomeBill.LocalReport.DataSources.Add(new Microsoft.Reporting.WinForms.ReportDataSource("DataSet_PhieuThu", dataSetPhieuThu.Tables[0]));
                reportViewer_IncomeBill.SetDisplayMode(Microsoft.Reporting.WinForms.DisplayMode.PrintLayout);
                reportViewer_IncomeBill.ZoomMode = Microsoft.Reporting.WinForms.ZoomMode.PageWidth;
            }

            this.reportViewer_IncomeBill.RefreshReport();
        }
    }
}
